package com.example.saveword.utils;

import static android.os.Build.VERSION_CODES.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.TextView;
import android.widget.Toast;

import com.example.saveword.R;
import com.example.saveword.dao.StudyRecordDao;
import com.example.saveword.model.StudyRecord;

public class mTimeUpdateReceiver extends BroadcastReceiver {
    private int overTime = 0;
    public StudyRecordDao studyRecordDao;
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.ACTION_TIME_TICK.equals(intent.getAction())){
            studyRecordDao = new StudyRecordDao(context);
            StudyRecord studyRecord = studyRecordDao.addOrGet();
            studyRecord.setLearnTime(studyRecord.getLearnTime() + 1);
            studyRecordDao.update(studyRecord);
            overTime ++;
            Toast.makeText(context, "又学习一分钟！", Toast.LENGTH_LONG).show();
            int now_time = (int) SPUtils.get(context, "LearnTime", 1);
            SPUtils.put(context, "LearnTime", now_time + 1);
        }
    }
    //返回打开时间(分钟)
    public int getOpenTime()
    {
        return overTime;
    }
}
